package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.ExcelUtil;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.system.domain.Detect;
import com.ruoyi.system.service.IDetectService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 检测单位 信息操作处理
 *
 * @author ruoyi
 * @date 2018-12-24
 */
@Controller
@RequestMapping("/system/detect")
public class DetectController extends BaseController {
    private String prefix = "system/detect" ;

    @Autowired
    private IDetectService detectService;

    @RequiresPermissions("system:detect:view")
    @GetMapping()
    public String detect() {
        return prefix + "/detect" ;
    }

    /**
     * 查询检测单位列表
     */
    @RequiresPermissions("system:detect:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Detect detect) {
        startPage();
        List<Detect> list = detectService.selectDetectList(detect);
        return getDataTable(list);
    }


    /**
     * 导出检测单位列表
     */
    @RequiresPermissions("system:detect:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Detect detect) {
        List<Detect> list = detectService.selectDetectList(detect);
        ExcelUtil<Detect> util = new ExcelUtil<Detect>(Detect.class);
        return util.exportExcel(list, "detect");
    }

    /**
     * 新增检测单位
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add" ;
    }

    /**
     * 新增保存检测单位
     */
    @RequiresPermissions("system:detect:add")
    @Log(title = "检测单位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Detect detect) {
        return toAjax(detectService.insertDetect(detect));
    }

    /**
     * 修改检测单位
     */
    @GetMapping("/edit/{detectId}")
    public String edit(@PathVariable("detectId") Integer detectId, ModelMap mmap) {
        Detect detect = detectService.selectDetectById(detectId);
        mmap.put("detect", detect);
        return prefix + "/edit" ;
    }

    /**
     * 修改保存检测单位
     */
    @RequiresPermissions("system:detect:edit")
    @Log(title = "检测单位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Detect detect) {
        return toAjax(detectService.updateDetect(detect));
    }

    /**
     * 删除检测单位
     */
    @RequiresPermissions("system:detect:remove")
    @Log(title = "检测单位", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(detectService.deleteDetectByIds(ids));
    }

}
